﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <%@ include file="/WEB-INF/views/modules/commons/head.jsp" %>
    <!-- 组件的css -->
    <link rel="stylesheet" href="<s:url value="/assets/web/common/lulu_zujian/ui.css"></s:url>">
    <!-- 用户管理 CSS -->
    <link rel="stylesheet" href="<s:url value="/assets/web/css/user/userManger.css"></s:url>">
    <style>
        /* 公用边距 */
        #content-main {
            padding: 0 20px 0;
        }
    </style>
    <title>用户管理</title>
</head>

<body class="bgcolor">
<%@ include file="/WEB-INF/views/modules/commons/nav.jsp" %>
<%@ include file="/WEB-INF/views/modules/commons/menu.jsp" %>
<table></table>
<div class="av row J_mainContent" id="content-main">
    <div class="user-manger" style="display: block;">
        <div class="container" style="padding-top: 10px;">
            <ul class="branchType-btn">
                <li class="branchTypeBtn" id = "ownerUnit_btn">业主单位</li>
                <li class="branchTypeBtn" id = "approval_btn">审批部门</li>
                <li class="branchTypeBtn" id = "inspection_btn">督查部门</li>
            </ul>
            <ul class="project-btn">
                <li class="primary">添加用户</li>
                <li class="warning">查询用户</li>
                <%--隐藏查询总页数--%>
                <li class="pages" style="display: none;"></li>
                <li class="pages" style="display: none;"></li>
                <%--隐藏修改用户当前页--%>
                <li id="page" style="display: none;"></li>
            </ul>
        </div>
        <div class="container">
            <table class="project-info">
                <thead>
                <tr>
                    <th>用户名称</th>
                    <th>电话</th>
                    <th>责任单位</th>
                    <th>单位类型</th>
                    <th>角色</th>
                    <th>操作</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="main">

                <%--<c:forEach "${list}" var="list">--%>
                <%--<tr>--%>
                <%--<td>${list.name}</td>--%>
                <%--<td>${list.phone}</td>--%>
                <%--<td>${list.branch}</td>--%>
                <%--<td>${list.role}</td>--%>
                <%--<td class="delUser" data-sysId="${list.sysId}">--%>
                <%--删除用户--%>
                <%--</td>--%>
                <%--<td class="update" data-sysId="${list.sysId}" data-branch="${list.branch}"--%>
                <%--data-name="${list.name}" data-phone="${list.phone}">修改用户--%>
                <%--</td>--%>
                <%--</tr>--%>
                <%--</c:forEach>--%>

                </tbody>
            </table>
        </div>

        <div class="footer">
            <ul class="pagination" id="pagination0"></ul>
        </div>

        <div class="shade"></div>

        <div class="model-container">
            <!-- 添加用户 -->
            <div class="adduser" style="display: none;">
                <p class="title">添加用户
                    <span>&times;</span>
                </p>
                <div class="add-page  text-center">
                    <form role="form" action="<s:url value="/hardWork/doAddUser"></s:url>" method="post">
                        <input type="text" class="name" name="name" placeholder="姓名" required>
                        <br>
                        <input type="text" id="userphone" class="phone" name="phone" placeholder="电话(电话号码不能重复)"
                               required>
                        <div style="color:red;display: none;" class="phone-error">电话号码重复，请重新输入</div>
                        <br>
                        <input type="text" class="password" name="password" placeholder="密码" required>
                        <br>
                        <select name="branchType" id="branch_type" class="res_dept">
                            <option value="0">业主</option>
                            <option value="1">部门</option>
                            <option value="2">攻坚办</option>
                            <option value="4">督查相关单位</option>
                        </select>
                        <br>
                        <input type="text" name="branch" placeholder="单位名称"/>
                        <br>
                        <select name="role" placeholder="职位" class="roles">
                            <option value="领导">领导</option>
                            <option value="经办人">经办人</option>
                            <option value="责任人">责任人</option>
                        </select>
                        <br>
                        <button type="submit" class="btn btn-primary  add-btn">添加用户</button>
                    </form>
                </div>
            </div>
            <!-- 查询用户 -->
            <div class="queryuser" style="display: none;">
                <p class="title">查询用户
                    <span>&times;</span>
                </p>

                <div class="text-center  form-2">
                    <div>
                        <input type="text" name="name" placeholder="请输入姓名">
                    </div>
                    <div>
                        <input type="text" name="phone" placeholder="请输入电话号码">
                    </div>
                    <div>
                        <select name="branch" placeholder="责任单位" class="res-dept-1">
                            <option value="">责任单位</option>
                            <c:forEach items="${deptList}" var="deptList">
                                <option value="${deptList}">${deptList}</option>
                            </c:forEach>

                        </select>
                    </div>
                    <div>
                        <select name="role" placeholder="角色" class="role-1">
                            <option value="">角色</option>
                            <option value="领导">领导</option>
                            <option value="经办人">经办人</option>
                            <option value="责任人">责任人</option>
                        </select>
                    </div>
                    <button id="queryuser">查询用户</button>
                </div>
            </div>
            <!--修改用户  -->
            <div class="updateuser" style="display: none;">
                <p class="title">修改用户
                    <span>&times;</span>
                </p>
                <div class="text-center  form-3">
                    <div>
                        <input type="text" name="name" placeholder="${bnpUser.name}">
                    </div>
                    <div>
                        <input type="text" name="phone" placeholder="${bnpUser.phone}">
                    </div>
                    <div>
                        <select name="branch_type" class="res-dept-1">
                            <option value="0">业主</option>
                            <option value="1">部门</option>
                            <option value="2">攻坚办</option>
                            <option value="4">督查组</option>
                        </select>
                    </div>
                    <div>
                        <input type="text" name="branch" placeholder="单位名称" placeholder="${bnpUser.branch}"/>
                    </div>
                    <div>
                        <select name="role" class="update-role">
                            <option value="">角色</option>
                            <option value="领导">领导</option>
                            <option value="经办人">经办人</option>
                            <option value="责任人">责任人</option>
                        </select>
                    </div>
                    <div style="display: none">
                        用户id<input type="text" name="sysid" placeholder="${bnpUser.sysId}">
                    </div>
                    <button id="updateuser">提交</button>
                </div>
            </div>
            <%--删除用户--%>
            <div class="deleteUser" style="display: none;">
                <p class="title">是否确定删除该用户
                    <span>&times;</span>
                </p>
                <form class="text-center  form-4" role="form" action="<s:url value="/hardWork/delete"></s:url>">
                    <div style="display: none">
                        id<input type="text" name="sysid" placeholder="请输入姓名">
                    </div>

                    <button id="deleteUser" type="submit">确定</button>
                    <div class="cancel" style="display: inline-block">取消</div>
                </form>
            </div>
        </div>
    </div>
</div>
<%@ include file="/WEB-INF/views/modules/commons/foot.jsp" %>

<script>
    <%--分页请求--%>
    var pages = $('#pagination0').jqPaginator({
        totalPages: ${totalPage},
        visiblePages: 5,
        currentPage: 1,
        first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
        onPageChange: function (num) {
            $('#text').html('当前第' + num + '页');
            $.ajax({
                type: "POST",
                url: "/hardWork/go/lists",
                dataType: "json",
                data: ({"page": num - 1}),
                success: function (model) {
                    var html = "";
                    for (var i = 0; i < model.model.length; i++) {
                        var list = model.model[i];
                        var branchType;
                        if(list.branchType == "0"){
                            branchType = "业主单位";
                        }else if(list.branchType == "1"){
                            branchType = "审批部门";
                        }else if(list.branchType == "4"){
                            branchType = "督查组";
                        }else{
                            branchType = "管理员";
                        }
                        html += "<tr class =\"" + i + "\">" + "<td>" + list.name
                            + "</td>" +
                            "+<td>" + list.phone + "</td>" +
                            "+<td>" + (list.branch == undefined ? "" : list.branch) + "</td>" +
                            "+<td>" + (branchType) + "</td>" +
                            "+<td>" + (list.role == undefined ? "" : list.role) + "</td>"
                            + "<td class=\"delUser\" data-sysId=\"" + list.sysId + "\">删除用户</td>" +
                            "<td class=\"update\" data-sysId=\"" + list.sysId + "\" data-branchtype=\"" + list.branchType + "\" data-branch=\"" + list.branch + "\" data-name=\"" + list.name + "\"   data-role=\"" + list.role + "\"     data-phone=\"" + list.phone + "\">修改用户</td>"
                            + "</tr>";
                    }
                    $("#main").html(html);
                    $("#page").html(num);
                },
                error: function (model) {
                }
            })
        }
    });

    <%--查询用户请求--%>
    $(function () {
        $("#queryuser").click(function () {
            $('#pagination0').jqPaginator({
                totalPages: 1,
                visiblePages: 5,
                currentPage: 1,
                first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
                prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
                next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
                last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
                page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
                onPageChange: function (num) {
                    var username = $(".form-2>div:first-child>input").val();
                    var userphone = $(".form-2>div:nth-child(2)>input").val();
                    var resdept = $(".res-dept-1>option:selected").val();
                    console.log(resdept);
                    var role = $(".role-1>option:selected").val();
                    console.log(role);
                    $('#text').html('当前第' + num + '页');
                    $.ajax({
                        type: "POST",
                        url: "/hardWork/go/lists",
                        dataType: "json",
                        data: {page: num - 1, name: username, phone: userphone, branch: resdept, role: role},
                        success: function (model) {
                            var html = "";
                            for (var i = 0; i < model.model.length; i++) {
                                var list = model.model[i];
                                var branchType;
                                if(list.branchType == "0"){
                                    branchType = "业主单位";
                                }else if(list.branchType == "1"){
                                    branchType = "审批部门";
                                }else if(list.branchType == "4"){
                                    branchType = "督查组";
                                }else{
                                    branchType = "管理员";
                                }
                                html += "<tr>" + "<td>" + list.name
                                    + "</td>" +
                                    "+<td>" + list.phone + "</td>" +
                                    "+<td>" + (list.branch == undefined ? "" : list.branch) + "</td>" +
                                    "+<td>" + (branchType) + "</td>" +
                                    "+<td>" + (list.role == undefined ? "" : list.role) + "</td>"
                                    + "<td class=\"delUser\" data-sysId=\"" + list.sysId + "\">删除用户</td>" +
                                    "<td class=\"update\" data-sysId=\"" + list.sysId + "\" data-branchtype=\"" + list.branchType + "\" data-branch=\"" + list.branch + "\" data-name=\"" + list.name + "\" data-role=\"" + list.role + "\" data-phone=\"" + list.phone + "\">修改用户</td>"
                                    + "</tr>";
                            }
                            $(".shade").fadeOut(1);
                            $(".model-container").fadeOut(1);
                            $("#main").html(html);
                            //赋值总页数
                            $(".pages").html(model.totalPage);
                            pagg = Number($(".pages").html());
                            //调用分页插件修改查询总页数
                            $('#pagination0').jqPaginator('option', {
                                totalPages: pagg,
                            });
                        },
                        error: function (model) {
                        }
                    })
                }
            });
        });

        $("#ownerUnit_btn").click(function () {
            $('#pagination0').jqPaginator({
                totalPages: 1,
                visiblePages: 5,
                currentPage: 1,
                first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
                prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
                next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
                last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
                page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
                onPageChange: function (num) {
                    var username = $(".form-2>div:first-child>input").val();
                    var userphone = $(".form-2>div:nth-child(2)>input").val();
                    var resdept = $(".res-dept-1>option:selected").val();
                    console.log(resdept);
                    var role = $(".role-1>option:selected").val();
                    console.log(role);
                    $('#text').html('当前第' + num + '页');
                    $.ajax({
                        type: "POST",
                        url: "/hardWork/go/lists",
                        dataType: "json",
                        data: {page: num - 1, branchType: '0'},
                        success: function (model) {
                            var html = "";
                            for (var i = 0; i < model.model.length; i++) {
                                var list = model.model[i];
                                var branchType;
                                if(list.branchType == "0"){
                                    branchType = "业主单位";
                                }else if(list.branchType == "1"){
                                    branchType = "审批部门";
                                }else if(list.branchType == "4"){
                                    branchType = "督查组";
                                }else{
                                    branchType = "管理员";
                                }
                                html += "<tr>" + "<td>" + list.name
                                    + "</td>" +
                                    "+<td>" + list.phone + "</td>" +
                                    "+<td>" + (list.branch == undefined ? "" : list.branch) + "</td>" +
                                    "+<td>" + (branchType) + "</td>" +
                                    "+<td>" + (list.role == undefined ? "" : list.role) + "</td>"
                                    + "<td class=\"delUser\" data-sysId=\"" + list.sysId + "\">删除用户</td>" +
                                    "<td class=\"update\" data-sysId=\"" + list.sysId + "\" data-branchtype=\"" + list.branchType + "\" data-branch=\"" + list.branch + "\" data-name=\"" + list.name + "\" data-role=\"" + list.role + "\" data-phone=\"" + list.phone + "\">修改用户</td>"
                                    + "</tr>";
                            }
                            $(".shade").fadeOut(1);
                            $(".model-container").fadeOut(1);
                            $("#main").html(html);
                            //赋值总页数
                            $(".pages").html(model.totalPage);
                            pagg = Number($(".pages").html());
                            //调用分页插件修改查询总页数
                            $('#pagination0').jqPaginator('option', {
                                totalPages: pagg,
                            });
                        },
                        error: function (model) {
                        }
                    })
                }
            });
        });


        $("#approval_btn").click(function () {
            $('#pagination0').jqPaginator({
                totalPages: 1,
                visiblePages: 5,
                currentPage: 1,
                first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
                prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
                next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
                last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
                page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
                onPageChange: function (num) {
                    var username = $(".form-2>div:first-child>input").val();
                    var userphone = $(".form-2>div:nth-child(2)>input").val();
                    var resdept = $(".res-dept-1>option:selected").val();
                    console.log(resdept);
                    var role = $(".role-1>option:selected").val();
                    console.log(role);
                    $('#text').html('当前第' + num + '页');
                    $.ajax({
                        type: "POST",
                        url: "/hardWork/go/lists",
                        dataType: "json",
                        data: {page: num - 1, branchType: '1'},
                        success: function (model) {
                            var html = "";
                            for (var i = 0; i < model.model.length; i++) {
                                var list = model.model[i];
                                var branchType;
                                if(list.branchType == "0"){
                                    branchType = "业主单位";
                                }else if(list.branchType == "1"){
                                    branchType = "审批部门";
                                }else if(list.branchType == "4"){
                                    branchType = "督查组";
                                }else{
                                    branchType = "管理员";
                                }
                                html += "<tr>" + "<td>" + list.name
                                    + "</td>" +
                                    "+<td>" + list.phone + "</td>" +
                                    "+<td>" + (list.branch == undefined ? "" : list.branch) + "</td>" +
                                    "+<td>" + (branchType) + "</td>" +
                                    "+<td>" + (list.role == undefined ? "" : list.role) + "</td>"
                                    + "<td class=\"delUser\" data-sysId=\"" + list.sysId + "\">删除用户</td>" +
                                    "<td class=\"update\" data-sysId=\"" + list.sysId + "\" data-branchtype=\"" + list.branchType + "\" data-branch=\"" + list.branch + "\" data-name=\"" + list.name + "\" data-role=\"" + list.role + "\" data-phone=\"" + list.phone + "\">修改用户</td>"
                                    + "</tr>";
                            }
                            $(".shade").fadeOut(1);
                            $(".model-container").fadeOut(1);
                            $("#main").html(html);
                            //赋值总页数
                            $(".pages").html(model.totalPage);
                            pagg = Number($(".pages").html());
                            //调用分页插件修改查询总页数
                            $('#pagination0').jqPaginator('option', {
                                totalPages: pagg,
                            });
                        },
                        error: function (model) {
                        }
                    })
                }
            });
        });


        $("#inspection_btn").click(function () {
            $('#pagination0').jqPaginator({
                totalPages: 1,
                visiblePages: 5,
                currentPage: 1,
                first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
                prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
                next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
                last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
                page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
                onPageChange: function (num) {
                    var username = $(".form-2>div:first-child>input").val();
                    var userphone = $(".form-2>div:nth-child(2)>input").val();
                    var resdept = $(".res-dept-1>option:selected").val();
                    console.log(resdept);
                    var role = $(".role-1>option:selected").val();
                    console.log(role);
                    $('#text').html('当前第' + num + '页');
                    $.ajax({
                        type: "POST",
                        url: "/hardWork/go/lists",
                        dataType: "json",
                        data: {page: num - 1, branchType: '4', isGroupCode:"0"},
                        success: function (model) {
                            var html = "";
                            for (var i = 0; i < model.model.length; i++) {
                                var list = model.model[i];
                                var branchType;
                                if(list.branchType == "0"){
                                    branchType = "业主单位";
                                }else if(list.branchType == "1"){
                                    branchType = "审批部门";
                                }else if(list.branchType == "4"){
                                    branchType = "督查组";
                                }else{
                                    branchType = "管理员";
                                }
                                html += "<tr>" + "<td>" + list.name
                                    + "</td>" +
                                    "+<td>" + list.phone + "</td>" +
                                    "+<td>" + (list.branch == undefined ? "" : list.branch) + "</td>" +
                                    "+<td>" + (branchType) + "</td>" +
                                    "+<td>" + (list.role == undefined ? "" : list.role) + "</td>"
                                    + "<td class=\"delUser\" data-sysId=\"" + list.sysId + "\">删除用户</td>" +
                                    "<td class=\"update\" data-sysId=\"" + list.sysId + "\" data-branchtype=\"" + list.branchType + "\" data-branch=\"" + list.branch + "\" data-name=\"" + list.name + "\" data-role=\"" + list.role + "\" data-phone=\"" + list.phone + "\">修改用户</td>"
                                    + "</tr>";
                            }
                            $(".shade").fadeOut(1);
                            $(".model-container").fadeOut(1);
                            $("#main").html(html);
                            //赋值总页数
                            $(".pages").html(model.totalPage);
                            pagg = Number($(".pages").html());
                            //调用分页插件修改查询总页数
                            $('#pagination0').jqPaginator('option', {
                                totalPages: pagg,
                            });
                        },
                        error: function (model) {
                        }
                    })
                }
            });
        });

    })

    //    修改用户
    $(function () {
        $("#updateuser").click(function () {
            var username = $(".form-3>div:first-child>input").val();
            var userphone = $(".form-3>div:nth-child(2)>input").val();
            var branchType = $(".form-3>div:nth-child(3)>select>option:selected").val();
            var branch = $(".form-3>div:nth-child(4)>input").val();
            var role = $(".update-role>option:selected").val();
            var id = $(".form-3>div:nth-child(6)>input").val();
            var num = $("#page").html();
            $.ajax({
                type: "POST",
                url: "/hardWork/update",
                dataType: "json",
                data: {
                    page: num - 1,
                    name: username,
                    phone: userphone,
                    branchType: branchType,
                    branch: branch,
                    sysid: id,
                    role: role
                },
                success: function (model) {
                    var html = "";
                    for (var i = 0; i < model.model.length; i++) {
                        var list = model.model[i];
                        html += "<tr>" + "<td>" + list.name
                            + "</td>" +
                            "+<td>" + list.phone + "</td>" +
                            "+<td>" + (list.branch == undefined ? "" : list.branch) + "</td>" +
                            "+<td>" + (list.role == undefined ? "" : list.role) + "</td>"
                            + "<td class=\"delUser\" data-sysId=\"" + list.sysId + "\">删除用户</td>" +
                            "<td class=\"update\" data-sysId=\"" + list.sysId + "\" data-branchtype=\"" + list.branchType + "\" data-branch=\"" + list.branch + "\" data-name=\"" + list.name + "\" data-role=\"" + list.role + "\" data-phone=\"" + list.phone + "\">修改用户</td>"
                            + "</tr>";
                    }
                    $(".shade").fadeOut(1);
                    $(".model-container").fadeOut(1);
                    $("#main").html(html);
                },
                error: function (model) {
                }
            })
        });
    })

    //模态框设置节点
    $(function () {
        //浏览器大小发生改变
        $(window).resize(function () {
            showShade();
        });

        //模态框出现
        // 添加用户
        $(".primary").bind("click", function () {
            $(".shade").show();
            $(".model-container").show();
            showShade();
            $(".adduser").show();
            $(".updateuser").hide();
            $(".queryuser").hide();
            $(".deleteUser").hide();
            showShade();
        });

        //查询用户
        $(".warning").bind("click", function () {
            $(".shade").show();
            $(".model-container").show();
            showShade();
            $(".queryuser").show();
            $(".updateuser").hide();
            $(".adduser").hide();
            $(".deleteUser").hide();
            showShade();
        });

        // 修改用户
        $("#main").on("click", ".update", function () {
            $(".shade").show();
            $(".model-container").show();
            showShade();
            $(".updateuser").show();
            $(".adduser").hide();
            $(".queryuser").hide();
            $(".deleteUser").hide();
            showShade();
        });
        // 删除用户
        $("#main").on("click", ".delUser", function () {
            $(".shade").show();
            $(".model-container").show();
            showShade();
            $(".deleteUser").show();
            $(".adduser").hide();
            $(".queryuser").hide();
            $(".updateuser").hide();
            showShade();
        });
        //点击span关闭
        $(".title>span,.shade").bind("click", function () {
            $(".shade").fadeOut(1);
            $(".model-container").fadeOut(1);
        });


        //添加用户判断号码是否重复
        $("#userphone").blur(function () {
            var phone = $(this).val();
            console.log(phone);
            $.ajax({
                type: "GET",
                url: "/hardWork/verifyPhoneExist",
                dataType: "json",
                data: {phone: phone},
                success: function (data) {
                    if (data) {
                        $(".phone-error").css("display", "none");
                        $(".add-btn").attr("disabled", false);
                    } else {
                        $(".phone-error").css("display", "block");
                        $(".add-btn").attr("disabled", true);
                    }


                }
            })
        });


        //居中显示
        function showShade() {
            var $vW = $(window).width();
            var $w = $(".model-container").outerWidth();
            var $vH = $(window).height();
            var $h = $(".model-container").outerHeight();
            $(".model-container").css({
                "left": ($vW - $w) / 2.1 + "px",
                "top": ($vH - $h) / 2.5 + "px"
            });
        };
        $(document).keyup(function (ev) {
            //                alert(ev.keyCode);  获取esc的键码27
            if (ev.keyCode == 27) {
                //                    $("span").click();
                //模拟事件
                $("span").trigger("click");
            }
        })
    })

    //    修改用户
    $(".project-info").on("click", ".update", function () {
        var lname = $(this).data("name"); //用户名
        $(".form-3>div:nth-child(1)>input").val(lname);

        var lphone = $(this).data("phone"); //电话号码
        $(".form-3>div:nth-child(2)>input").val(lphone);

        var branchType = $(this).data("branchtype"); //责任单位类型
        var ops = $(".form-3>div:nth-child(3)>select>option");

        var lbranch = $(this).data("branch"); //责任单位
        $(".form-3>div:nth-child(4)>input").val(lbranch);

        var role = $(this).data("role"); //角色
        var opsrole = $(".form-3>div:nth-child(5)>select>option");

        switch (branchType) {
            case 0:
                ops[0].setAttribute("selected", "true");
                ops[1].removeAttribute("selected");
                ops[2].removeAttribute("selected");
                break;
            case 1:
                ops[1].setAttribute("selected", "true");
                ops[0].removeAttribute("selected");
                ops[2].removeAttribute("selected");
                break;
            case 2:
                ops[2].setAttribute("selected", "true");
                ops[0].removeAttribute("selected");
                ops[1].removeAttribute("selected");
                break;
        }
        for (var i = 0; i < opsrole.length; i++) {
            if (opsrole[i].innerHTML == role) {
                opsrole[i].setAttribute("selected", "true");
            } else {
                opsrole[i].removeAttribute("selected");
            }
        }

        var lid = $(this).data("sysid"); //用户id
        $(".form-3>div:nth-child(6)>input").val(lid);
    });

    //删除用户
    $(".project-info").on("click", ".delUser", function () {
        var lid = $(this).data("sysid"); //用户名。
        $(".form-4>div:nth-child(1)>input").val(lid);
    });
    //    关闭模态框
    $(".cancel").click(function () {
        $(".shade").fadeOut(1);
        $(".model-container").fadeOut(1);
    });

    //添加用户选择单位类型下拉框联动
    //下拉框连动
    function showBranch() {
        // 获取下拉框主键
        var branch_type = $("#branch_type").find('option:selected').val();
        var branch = $("#branch");
        console.log(branch);
        // branch.empty();
        $.ajax({
            type: "get",
            contentType: "application/json",
            url: "/hardWork/showBranch",
            data: {branch_type: branch_type},
            success: function (data) {
                if (data.length != "" && data.length != null) {
                    for (var i = 0; i < data.length; i++) {
                        branch.append("<option value=" + data[i].branch + ">" + data[i].branch + "</option>");
                    }
                } else {
                    branch.append("<option value=" + branch_type + ">---无---</option>");
                }
            }
        });
    }
</script>
</body>
</html>